package org.internet.UDP;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;

public class SendMessageDemo {
    public static void main(String[] args) throws IOException {
        //1.创建发送端
        DatagramSocket ds = new DatagramSocket();

        //2.创建集装箱，打包数据
        String message = "123456789";
        byte[] buf = message.getBytes();
        InetAddress address = InetAddress.getByName("127.0.0.1");
        int port = 10086;
        DatagramPacket dp = new DatagramPacket(buf, 0, buf.length, address, port);
        InetAddress address1 = InetAddress.getByName("127.0.0.1");
        //3.发送数据
        ds.send(dp);

        //4.关闭资源
        ds.close();
    }
}
